package cn.wtg.kotlinlib.bindingAdapter

import androidx.databinding.BindingAdapter
import androidx.recyclerview.widget.RecyclerView

/**
 * author: wtg
 * date:2020/3/16 0016
 * desc: 列表的数据绑定adapter
 */
object RecyclerViewBindingAdapter {
    /**
     * 设置列表的 布局管理器和缓存大小和item宽高是否是固定值
     *
     * @param recyclerView           recyclerView
     * @param layout_item_cache_size 缓存的item数量
     * @param layout_has_fixed_size  item是否是固定宽高
     * @param adapter                适配器
     */
    @BindingAdapter(
        value = ["binding_recycler_item_cache_size", "binding_recycler_has_fixed_size", "binding_recycler_adapter"],
        requireAll = false
    )
    fun layoutManager(
        recyclerView: RecyclerView,
        binding_recycler_item_cache_size: Int,
        binding_recycler_has_fixed_size: Boolean,
        binding_recycler_adapter: RecyclerView.Adapter<*>?
    ) {
        if (binding_recycler_adapter != null) {
            recyclerView.adapter = binding_recycler_adapter
        }
        if (binding_recycler_item_cache_size > 0) {
            recyclerView.setItemViewCacheSize(binding_recycler_item_cache_size)
        }
    }
}